package com.myshop.controller;


import com.myshop.entity.Product;

import com.myshop.entity.R;
import com.myshop.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * (Product)表控制层
 *
 * @author makejava
 * @since 2023-07-21 17:19:10
 */
@CrossOrigin
@RestController
@RequestMapping("/newsInfo")
public class ProductController {

    @Autowired
    private ProductService productService;

    /**
     * 上架商品
     */
    @RequestMapping("/insert")
    public R add(Product product) {
        productService.save(product);
        return R.succ("上架商品");
    }

    /**
     * 新闻列表

     * @return
     */
    @RequestMapping("/list1")
    public R list(Product product) {
        List<Product> newsInfos = productService.listBySearch(product);
        System.out.println("来自商品的列表" + newsInfos);
        return R.succ(newsInfos);
    }

    /**
     * 下架商品
     */
    @RequestMapping("/update")
    public R stateupdate(Product product) {
//        UpdateChainWrapper<Product> update = productService.update();
        boolean b = productService.updateById(product);
        System.out.println("获取下架id,state-->" + b);
        return R.succ(b);

    }


/**
 * 商品模块的商品实体(Product)表控制层
 *
 * @author makejava
 * @since 2023-07-21 16:17:55
 */
    /**
     * 展示的商品
     *
     * @return
     */
    @RequestMapping("/list")
    public R list() {
        return R.succ(productService.list());
    }
}
